<?php
// +----------------------------------------------------------------------
// | ZGUAN [ 致力于帮助更多的中小企业物联网转型 ]
// +----------------------------------------------------------------------
// | Copyright (c) 2017~2024 https://www.zguan.cn All rights reserved.
// +----------------------------------------------------------------------
// | Licensed ZGUAN 并不是自由软件，未经许可不能去掉ZGUAN 相关版权
// +----------------------------------------------------------------------
// | Author: ZGUAN Team <admin@zguan.cn>  0769-82282996  15899929162
// +----------------------------------------------------------------------
namespace app\common\dao\property\auth;

use app\common\dao\BaseDao;
use app\traits\CategoryDao;
use app\common\model\property\auth\PropertyAuthRuleModel;

class PropertyAuthRuleDao extends BaseDao
{

    use CategoryDao;

    /**
     * @return PropertyAuthRuleModel
     */
    protected function getModel(): string
    {
        return PropertyAuthRuleModel::class;
    }

    public function search(array $where)
    {
        $query = $this->getModel()::getDB()->order('sort desc');
        if (isset($where['is_menu'])) $query->where('is_menu', (int)$where['is_menu']);
        if (isset($where['id'])) {
            if (is_array($where['id'])) {
                $query->where('id', 'in', $where['id']);
            } else {
                $query->where('id', (int)$where['id']);
            }
        }
        return $query;
    }

    /**
     * 获取菜单列表
     * @param $where
     * @param $field
     * @return mixed
     *
     * @author Amos
     * 2024-01-07 15:40
     */
    public function getMenuList($where = [])
    {
        return $this->search($where)
            ->order('sort desc')
            ->field('id,rule_url,name,sort,pid,icon,is_menu')
            ->select();
    }

    /**
     * 查询某个字段
     * @param $where
     * @param $field
     * @return array
     *
     * @author Amos
     * 2024-01-16 20:45
     *
     */
    public function getColumn($where, $field)
    {
        return $this->search($where)
            ->column($field);
    }
}
